The present invention is in the general field of data processing, and provides a technique for accessing relational and other structured data from an object based application model.
An object based application model is an application model in an object oriented (OO) programming environment. Data stored statically, such as in a relational data base, can be presented in an object based application model and manipulated at run time, encapsulated in a self-contained entity called an object. In addition to data, the object contains its own instructions to perform operations on the data.
OO programming in general is based on the notion of inheritance; the attributes and methods invocable in an object are defined through a class hierarchy that permits functionality to be reused from one object to another when active objects are instantiated. The active objects are constructed in dynamic memory according to a set of constructors defined through class inheritance.
The manner in which access to the stored data is made through an active object must be specifically programmed, particularly if the data is stored in a structured format such as a relational database. As discussed in European Patent Application 0 690 375 A2 of International Business Machines Corporation for xe2x80x9cPersistent Object-Mapping In An Object-Oriented Environmentxe2x80x9d, published on Jan. 3, 1996, an object called a schema mapper can be employed to generate all of the database access code in the object. A sample of code to map an object with a single database table is provided in the published application. In order to map the object with data in multiple discrete tables, databases and/or memories, similar code would have to be generated in the object for each data access location.
The present invention is directed to structuring an object that can be used for simple and complex mappings to data, as well as various forms of data resource management. The object structure of the invention can be used for wrapping legacy code, as well as newly written object-based code.
The invention is also directed to structuring an object so that both vertical and horizontal slicing techniques on the inheritance hierarchies can be used.
Accordingly, the present invention provides a system for giving program data objects access to stored data, implemented in an object oriented programming environment. The system provides at least one object wrapper isolating access code for the stored data into reusable modules, and means for invoking said access code from the program data objects. Preferably, the object wrappers consist of a plurality of access code modules, each of which contains access code for a unique view of data accessed from multiple storage locations.
The present invention also provides an object builder tool implemented in software for mapping program data objects with stored data. The object tool includes means for wrapping blocks of access code to the stored data in reusable code modules, and means for inlining access code to the reusable code modules in the program data objects. Preferably, the means for wrapping blocks of access code to the stored data in reusable code modules consists of means for isolating attributes from methods in a given program data object, means for defining each of a set of attributes and methods for the given program data object in one or more one wrapper objects and sequentially mapping each attribute and method in the given data object to, respectively, at least one attribute and method in the one or more wrapper objects, and then means for generating the reusable code modules in the wrapper object(s) according to the defined attributes and methods. Also, preferably, the means for wrapping blocks of access code to the stored data in reusable code modules consists of means for wrapping blocks of access code to unique views of the stored data, with at least some views representing data accessed from multiple storage locations.
Additionally, the invention provides a method for creating wrappers for reusable code blocks for access to stored data. For each selected data object, the method consists of defining at least one persistent object instance, defining the attribute mapping from the data object to said at least one persistent object instance, defining the method mapping from the data object to said at least one persistent object instance, generating code to define said at least one persistent object according to the defined associations of data object attributes and methods, and generating inline code in the data object to invoke methods in said at least one persistent object to access the stored data.
The invention is also directed to a program storage device readable by a machine, that tangibly embodies a program of instructions executable by the machine for performing the above recited method steps.